import datetime

from dao.food_store import FoodStore
from utils.date import get_date_now
import time
from utils.RandUtil import generate_uuid
from utils.PutObjectUtil import putObject


class FoodService():
    def list(self):
        return FoodStore().list()

    def queryFoodByHollId(self, id, query):
        if len(id) != 0 and id != "null":
            return FoodStore().queryByDiningHollId(id)
        if query is not None and query!= "null":
            return FoodStore().selectBySearch(query)


        return FoodStore().list()

    def getDetail(self, id):
        return FoodStore().selectDetailById(id)

    def putFoodImg(self, data):
        baseUrl = "https://taritari-1306000991.cos.ap-chengdu.myqcloud.com/"
        imgUrl = "food/" + generate_uuid() + ".jpg"
        putObject(data, imgUrl)
        return baseUrl + imgUrl

    def getFoodType(self):
        return FoodStore().getFoodType()

    def getDingHall(self):
        return FoodStore().getDingHall()

    def addFood(self, food):
        food.create_time = datetime.datetime.now()
        return FoodStore().addFood(food)

    def deleteFood(self,id):
        return FoodStore().deleteFood(id)

    def updateFood(self,food,id):
        food.id = id
        return FoodStore().updateFood(food)

    def selectByAuthorId(self,authorId):
        return FoodStore().selectFoodByAuthorId(authorId)